package com.styytech.dadabao.test.clippicture;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.styytech.dadabao.R;
import com.styytech.dadabao.widge.clippicture.CameraBaseActivity;

import java.io.File;

public class ClippictureMainActivity extends CameraBaseActivity {
    /**
     * 上下文
     */
    private Context mContext;
    /**
     * 上传头像
     */
    private LinearLayout ll_photo;
    private ImageView iv_headimg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View rootView = getLayoutInflater().inflate(R.layout.activity_clippicture_main,null);
        setContentView(rootView);
        rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showCameraDialog(mContext, ll_photo);
            }
        });
        mContext = this;
        findView();
    }

    private void findView() {
        iv_headimg = (ImageView) findViewById(R.id.iv_headimg);
        ll_photo = (LinearLayout) findViewById(R.id.ll_photo);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_image) {
            showCameraDialog(mContext, ll_photo);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


    /**
     * 点击事件
     */
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.btn_takephoto:
                // requestCode == CAMERA_REQUEST_CODE 跳转到系统截图界面
                // requestCode == PIC_REQUEST_FROM_CAMERA 跳转到自定义截图界面
                // requestCode == PIC_TAKE_FROM_CAMERA 直接打开图片
                takePhoto(PIC_REQUEST_FROM_CAMERA);

                break;
            case R.id.btn_getphoto:
                // requestCode == PIC_REQUEST_FROM_LOCAL 跳转到自定义截图界面
                // requestCode == IMAGE_REQUEST_CODE 跳转到系统截图界面
                // requestCode == PIC_GET_FROM_CAMERA 直接从相册选取的图片
                getPhoto(PIC_REQUEST_FROM_LOCAL);
                break;
            default:
                break;
        }
    }


    @Override
    public String setSaveTempPhotoPath() {
        String rootdir = Environment
                .getExternalStorageDirectory().getAbsolutePath();
        String photoTempPath = rootdir
                + File.separator + "Dada"
                + File.separator + "images"
                + File.separator + "headImg.jpg";
        return photoTempPath;
    }

    @Override
    public void disposePicture(Bitmap photo) {
        iv_headimg.setImageBitmap(photo);
        // 隐藏
        hideCameraDialog(mContext, ll_photo);
    }
    @Override
    public Class skipClipActivityName() {
        Class clszz = ClipPictureActivity.class;
        return clszz;
    }

}
